View Javadoc
1 package junit.quilt.ui; 2 3 /*** 4 * ReportAction 5 * 6 * This is an action which runs a report 7 * on the current Collector. 8 */ 9 10 import junit.quilt.reports.*; 11 12 13 import javax.swing.JFileChooser; 14 import javax.swing.JFrame; 15 import java.awt.event.ActionEvent; 16 import java.io.*; 17 18 public class ReportAction 19 extends ResourceAction 20 { 21 private Quilt quilt; 22 public ReportAction(Quilt quilt, 23 String resName) { 24 super( resName ); 25 this.quilt = quilt; 26 } 27 28 private File getFile() 29 throws Exception 30 { 31 JFileChooser dialog = new JFileChooser(); 32 33 int status = dialog.showSaveDialog( new JFrame() ); 34 if (status == JFileChooser.CANCEL_OPTION) { 35 throw new Exception("Canceled"); 36 } else { 37 return dialog.getSelectedFile(); 38 } 39 } 40 41 public void actionPerformed( ActionEvent event ) { 42 String args[] = getArgs(); 43 File file = null; 44 45 try { 46 if (args.length == 0) { 47 // We have not file name. . . 48 file = getFile(); 49 } else { 50 file = new File(args[0]); 51 } 52 53 String className = (String) getValue("class.name"); 54 Class reportClass = Class.forName( className ); 55 56 Report report = (Report) reportClass.newInstance(); 57 58 report.writeReport( new FileOutputStream( file ), 59 quilt.getRegistry() ); 60 } catch (Exception e) { 61 System.err.println("Oops."); 62 e.printStackTrace(); 63 } 64 } 65 } 66 67 68

This page was automatically generated by Maven